home *** CD-ROM | disk | FTP | other *** search
- Path: savvy1.savvy.com!phil
- From: phil@savvy1.savvy.com (Phil Schwartz)
- Newsgroups: comp.lang.c
- Subject: function similar to strtok() needed
- Date: 22 Feb 1996 22:12:41 GMT
- Organization: Savvy Communications
- Message-ID: <4gipop$igp@savvy2.savvy.com>
- NNTP-Posting-Host: savvy1.savvy.com
- X-Newsreader: TIN [version 1.2 PL2]
-
-
- I want to be able to parse a line, say "this is a test&it better work!ok"
- and grab the tokens which I will consider to be anything except the
- space (" "), ampersand ("&") and exclamation point ("!"). Strtok() seems to
- be a good starting point:
-
- -----------------
- char *tokens = " !&";
- char *tok;
- char *string = "this is a test&it better work!ok";
-
- tok = strtok(string, tokens);
- while (tok != NULL) {
- printf("%s\n", tok);
- tok = strtok(NULL, tokens);
- }
- ...
- -----------------
-
-
- However, what if I want to know which of the characters (in tokens) was
- the separator between two tokens (tok)? For example, when tok is "test"
- the separator was a space and when tok is "it", the separator is the
- ampersand.
-
- I'm sure I could add write a hocked up routine to do this, but I figure
- there must be some elegant way of finding out this information.
-
- Any help is appreciated.
-
- Thanks,
-
- Phil Schwartz
- phil@savvy.com
-
-
-